//
//  MineViewController.m
//  网络FM
//
//  Created by dllo on 15/5/22.
//  Copyright (c) 2015年 dengzhicheng.com. All rights reserved.
//

#import "MineViewController.h"
#import "MineTableViewCell.h"
#import "LikeViewController.h"
#import "DownLoadViewController.h"
#import "HistoryViewController.h"
#import "SettingViewController.h"

#define width self.view.frame.size.width
#define height self.view.frame.size.height

@interface MineViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic ,retain) UIImageView *backImage;

@end

@implementation MineViewController

- (void)dealloc
{
    [_backImage release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self createView];
}


- (void)createView
{
    self.backImage = [[UIImageView alloc] initWithFrame:self.view.frame];
    self.backImage.userInteractionEnabled = YES;
    [_backImage setImage:[UIImage imageNamed:@"抽屉界面背景图.jpeg"]];
    [self.view addSubview:_backImage];
    [_backImage release];
    
    UIImageView *userImage = [[UIImageView alloc] initWithFrame:CGRectMake(width / 8, height / 10, width / 4, width / 4)];
    [userImage setImage:[UIImage imageNamed:@"头像.jpg"]];
    userImage.layer.cornerRadius = width / 8;
    userImage.clipsToBounds = YES;
    [_backImage addSubview:userImage];
    [userImage release];
    
    UIButton *loginButton = [[UIButton alloc] initWithFrame:CGRectMake(width / 8, height / 4, width / 4, height/ 20)];
    [loginButton setTitle:@"登录" forState:UIControlStateNormal];
    loginButton.titleLabel.font = [UIFont boldSystemFontOfSize:24];
    [loginButton setBackgroundColor:[UIColor clearColor]];
    [_backImage addSubview:loginButton];
    [loginButton release];
    
    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(10, height / 3, width / 2 - 10, height / 2) style:UITableViewStylePlain];
    table.rowHeight = height / 6;
    [table setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [table setBackgroundColor:[UIColor clearColor]];
    table.dataSource = self;
    table.delegate = self;
    [_backImage addSubview:table];
    [table release];
    
    UIButton *setButton = [[UIButton alloc] initWithFrame:CGRectMake(20, height / 10 * 9, 80, 40)];
    [setButton setImage:[UIImage imageNamed:@"设置.png"] forState:UIControlStateNormal];
    [setButton setTitle:@" 设置" forState:UIControlStateNormal];
    setButton.titleLabel.font = [UIFont boldSystemFontOfSize:20];
    [setButton setBackgroundColor:[UIColor clearColor]];
    [setButton addTarget:self action:@selector(setButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [_backImage addSubview:setButton];
    [setButton release];
    
}

- (void)setButtonClick:(UIButton *)button
{
    SettingViewController *set = [[SettingViewController alloc] init];
    [set setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self presentViewController:set animated:YES completion:nil];
    [set release];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[MineTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
    }
    [cell setBackgroundColor:[UIColor clearColor]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (indexPath.row == 0) {
        [cell.aImage setImage:[UIImage imageNamed:@"收藏图标.png"]];
        [cell.lable setText:@"我的收藏"];
        cell.lable.font = [UIFont boldSystemFontOfSize:18];
        cell.lable.textColor = [UIColor whiteColor];
        [cell.bImage setImage:[UIImage imageNamed:@"向右箭头.png"]];
    } else if (indexPath.row == 1)
    {
     
        [cell.aImage setImage:[UIImage imageNamed:@"我的下载.png"]];
        [cell.lable setText:@"我的下载"];
        cell.lable.font = [UIFont boldSystemFontOfSize:18];
        cell.lable.textColor = [UIColor whiteColor];
        [cell.bImage setImage:[UIImage imageNamed:@"向右箭头.png"]];
    } else if (indexPath.row == 2)
    {
        [cell.aImage setImage:[UIImage imageNamed:@"我的历史.png"]];
        [cell.lable setText:@"我的历史"];
        cell.lable.font = [UIFont boldSystemFontOfSize:18];
        cell.lable.textColor = [UIColor whiteColor];
        [cell.bImage setImage:[UIImage imageNamed:@"向右箭头.png"]];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    if (indexPath.row == 0) {
        LikeViewController *like = [[LikeViewController alloc] init];
        [like setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
        [self presentViewController:like animated:YES completion:nil];
        [like release];
    } else if (indexPath.row == 1)
    {
        DownLoadViewController *down = [[DownLoadViewController alloc] init];
        [down setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
        [self presentViewController:down animated:YES completion:nil];
        [down release];
    } else if (indexPath.row == 2)
    {
        HistoryViewController *history = [[HistoryViewController alloc] init];
        [history setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
        [self presentViewController:history animated:YES completion:nil];
        [history release];
    }
}







@end
